package com.xxxx.blog.service.serviceImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxxx.blog.entity.Comment;
import com.xxxx.blog.mapper.CommentMapper;
import com.xxxx.blog.service.CommentService;
import com.xxxx.blog.utils.Maps;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@AllArgsConstructor
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper,Comment> implements CommentService {

    private final CommentMapper commentMapper;

    public int create(Comment comment){
        return commentMapper.create(comment);
    }

    public int delete(Integer id){
        return commentMapper.delete(Maps.build(id).getMap());
    }

    public int update(Comment comment){
        return commentMapper.update(Maps.build(comment.getId()).beanToMapForUpdate(comment));
    }

    public PageInfo<Comment> query(Comment comment){
        if(comment != null && comment.getPage() != null){
            PageHelper.startPage(comment.getPage(),comment.getLimit());
        }
        List<Comment> list = commentMapper.query(Maps.build().beanToMap(comment));
        return new PageInfo<Comment>(list);
    }

    public Comment detail(Integer id){
        return commentMapper.detail(Maps.build(id).getMap());
    }

    public int count(Comment comment){
        return commentMapper.count(Maps.build().beanToMap(comment));
    }




}
